﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BusinessLayer.Tables;
using System.Data.SqlClient;

public partial class Admin_Stok : ChildPage
{
    #region Fields
    Db_Stok stok;
    Db_Barkot barkod;
    Db_Birim birim;
    Db_Fiyat fiyat;
    Db_Stok_Depo stokDepo;
    Db_Depo depo;
    Db_DovizTanim doviz;
    Db_Vergi vergi;
    Db_FiyatTanim FiyatTanim;
    DataTable dtBirim;
    DataTable dtBarkod;
    DataTable dtfiyat;
    DataTable dtStokDepo;
    DataTable dtDepo;
    DataTable dtDoviz;
    DataTable dtVergi;
    DataTable dtFiyatTanim;
    #endregion

    #region Functions
    private void DropDepo()
    {
        ListItem lst;
        depo = new Db_Depo();
        dtDepo = depo.GetAllRecord_Datatable("depo_kodu", "depo_adi");

        for (int i = 0; i < dtDepo.Rows.Count; i++)
        {
            lst = new ListItem();
            lst.Text = dtDepo.Rows[i][1].ToString();
            lst.Value = dtDepo.Rows[i][0].ToString();
            drpDepoKod.Items.Add(lst);
            drpFiyatDepoID.Items.Add(lst);
        }

    }
    private void DropDovizKdv()
    {
        ListItem lst;
        drpStokAlisKdv.Items.Clear();
        drpStokIadeKdv.Items.Clear();
        drpStokPerIadeKdv.Items.Clear();
        drpStokPerSatisKdv.Items.Clear();
        drpStokSatisKdv.Items.Clear();
        doviz = new Db_DovizTanim();
        dtDoviz = doviz.GetAllRecord_Datatable("doviz_id", "dvz_kisa_ad");
        vergi = new Db_Vergi();
        dtVergi = vergi.GetAllRecord_Datatable("vergi_id", "vergi_tanim");
        for (int vrg = 0; vrg < dtVergi.Rows.Count; vrg++)
        {
            lst = new ListItem();
            lst.Value = dtVergi.Rows[vrg][0].ToString();
            lst.Text = dtVergi.Rows[vrg][1].ToString();
            drpStokAlisKdv.Items.Add(lst);
            lst = new ListItem();
            lst.Value = dtVergi.Rows[vrg][0].ToString();
            lst.Text = dtVergi.Rows[vrg][1].ToString();
            drpStokIadeKdv.Items.Add(lst);
            lst = new ListItem();
            lst.Value = dtVergi.Rows[vrg][0].ToString();
            lst.Text = dtVergi.Rows[vrg][1].ToString();
            drpStokPerIadeKdv.Items.Add(lst);
            lst = new ListItem();
            lst.Value = dtVergi.Rows[vrg][0].ToString();
            lst.Text = dtVergi.Rows[vrg][1].ToString();
            drpStokPerSatisKdv.Items.Add(lst);
            lst = new ListItem();
            lst.Value = dtVergi.Rows[vrg][0].ToString();
            lst.Text = dtVergi.Rows[vrg][1].ToString();
            drpStokSatisKdv.Items.Add(lst);
        }
        for (int dvz = 0; dvz < dtDoviz.Rows.Count; dvz++)
        {
            lst = new ListItem();
            lst.Value = dtDoviz.Rows[dvz][0].ToString();
            lst.Text = dtDoviz.Rows[dvz][1].ToString();
            drpStokDovizTipi.Items.Add(lst);
        }
    }
    private void DropBirim(int stokid)
    {
        ListItem lst;
        birim = new Db_Birim();
        dtBirim = birim.GetAllRecord_Datatable2("SELECT birim_adi, birim_id FROM  TBL_0_BIRIM WHERE birim_stok_id =" + stokid);
        drpFiyatBirimNo.Items.Clear();
        drpBarkodBirimID.Items.Clear();
        for (int i = 0; i < dtBirim.Rows.Count; i++)
        {
            lst = new ListItem();
            lst.Text = dtBirim.Rows[i][0].ToString();
            lst.Value = dtBirim.Rows[i][1].ToString();
            drpBarkodBirimID.Items.Add(lst);
            lst = new ListItem();
            lst.Text = dtBirim.Rows[i][0].ToString();
            lst.Value = dtBirim.Rows[i][1].ToString();
            drpFiyatBirimNo.Items.Add(lst);
        }
    }
    private void DropBirim()
    {
        ListItem lst;
        birim = new Db_Birim();
        dtBirim = birim.GetAllRecord_Datatable("birim_adi", " birim_id ");
        for (int brm = 0; brm < dtBirim.Rows.Count; brm++)
        {
            lst = new ListItem();
            lst.Text = dtBirim.Rows[brm][0].ToString();
            lst.Value = dtBirim.Rows[brm][1].ToString();
            drpStokAlisBirim.Items.Add(lst);
            lst = new ListItem();
            lst.Text = dtBirim.Rows[brm][0].ToString();
            lst.Value = dtBirim.Rows[brm][1].ToString();
            drpStokSatisBirim.Items.Add(lst);
            lst = new ListItem();
            lst.Text = dtBirim.Rows[brm][0].ToString();
            lst.Value = dtBirim.Rows[brm][1].ToString();
            drpBarkodBirimID.Items.Add(lst);
            lst = new ListItem();
            lst.Text = dtBirim.Rows[brm][0].ToString();
            lst.Value = dtBirim.Rows[brm][1].ToString();
            drpFiyatBirimNo.Items.Add(lst);
        }
    }
    private void DropFiyatKod()
    {
        FiyatTanim = new Db_FiyatTanim();
        dtFiyatTanim = FiyatTanim.GetAllRecord_Datatable2("SELECT fyt_kod, fyt_adi FROM  TBL_0_FIYATTANIM");
        for (int i = 0; i < dtFiyatTanim.Rows.Count; i++)
        {
            ListItem lst = new ListItem();
            lst.Value = dtFiyatTanim.Rows[i][0].ToString();
            lst.Text = dtFiyatTanim.Rows[i][1].ToString();
            drpFiyatKod.Items.Add(lst);
        }
    }
    private void ClearArea()
    {
        int selectedTab = MenuItemStok.SelectedIndex;
        switch (selectedTab)
        {
            case 0:

                foreach (Control c in MenuItemStok.PageViews[0].Controls)
                {
                    if (c is CrmControls.CrmTextBox)
                    {
                        CrmControls.CrmTextBox textbox = c as CrmControls.CrmTextBox;
                        textbox.Text = "";
                    }
                    if (c is CrmControls.CrmDropDown)
                    {
                        CrmControls.CrmDropDown drop1 = c as CrmControls.CrmDropDown;
                        if (drop1.SelectedIndex != -1)
                            drop1.SelectedIndex = 0;
                    }
                }
                foreach (Control c2 in MenuItemStok.PageViews[1].Controls)
                {
                    if (c2 is CrmControls.CrmTextBox)
                    {
                        CrmControls.CrmTextBox text2 = c2 as CrmControls.CrmTextBox;
                        text2.Text = "";
                    }
                    if (c2 is CrmControls.CrmCheckBox)
                    {
                        CrmControls.CrmCheckBox chek = c2 as CrmControls.CrmCheckBox;
                        chek.Checked = false;
                    }
                    if (c2 is CrmControls.CrmDropDown)
                    {
                        CrmControls.CrmDropDown drop2 = c2 as CrmControls.CrmDropDown;
                        if (drop2.SelectedIndex != -1)
                            drop2.SelectedIndex = 0;
                    }
                }
                break;
            case 1:
                foreach (Control c in MenuItemStok.PageViews[0].Controls)
                {
                    if (c is CrmControls.CrmTextBox)
                    {
                        CrmControls.CrmTextBox textbox = c as CrmControls.CrmTextBox;
                        textbox.Text = "";
                    }
                    if (c is CrmControls.CrmDropDown)
                    {
                        CrmControls.CrmDropDown drop1 = c as CrmControls.CrmDropDown;
                        if (drop1.SelectedIndex != -1)
                            drop1.SelectedIndex = 0;
                    }
                }
                foreach (Control c2 in MenuItemStok.PageViews[1].Controls)
                {
                    if (c2 is CrmControls.CrmTextBox)
                    {
                        CrmControls.CrmTextBox text2 = c2 as CrmControls.CrmTextBox;
                        text2.Text = "";
                    }
                    if (c2 is CrmControls.CrmCheckBox)
                    {
                        CrmControls.CrmCheckBox chek = c2 as CrmControls.CrmCheckBox;
                        chek.Checked = false;
                    }
                    if (c2 is CrmControls.CrmDropDown)
                    {
                        CrmControls.CrmDropDown drop2 = c2 as CrmControls.CrmDropDown;
                        if (drop2.SelectedIndex != -1)
                            drop2.SelectedIndex = 0;
                    }
                }
                break;
            case 2:
                foreach (Control c3 in MenuItemStok.PageViews[2].Controls)
                {
                    if (c3 is CrmControls.CrmTextBox)
                    {
                        CrmControls.CrmTextBox text3 = c3 as CrmControls.CrmTextBox;
                        text3.Text = "";
                    }
                }
                break;

            case 3:
                foreach (Control c4 in MenuItemStok.PageViews[3].Controls)
                {
                    if (c4 is CrmControls.CrmTextBox)
                    {
                        CrmControls.CrmTextBox text4 = c4 as CrmControls.CrmTextBox;
                        text4.Text = "";
                    }
                    if (c4 is CrmControls.CrmDropDown)
                    {
                        CrmControls.CrmDropDown drop = c4 as CrmControls.CrmDropDown;
                        if (drop.SelectedIndex != -1)
                            drop.SelectedIndex = 0;
                    }
                }
                break;

            case 4:

                foreach (Control c5 in MenuItemStok.PageViews[4].Controls)
                {
                    if (c5 is CrmControls.CrmTextBox)
                    {
                        CrmControls.CrmTextBox text5 = c5 as CrmControls.CrmTextBox;
                        text5.Text = "";
                    }
                    if (c5 is CrmControls.CrmDropDown)
                    {
                        CrmControls.CrmDropDown drop2 = c5 as CrmControls.CrmDropDown;
                        if (drop2.SelectedIndex != -1)
                            drop2.SelectedIndex = 0;
                    }
                    if (c5 is CrmControls.CrmCheckBox)
                    {
                        CrmControls.CrmCheckBox chek2 = c5 as CrmControls.CrmCheckBox;
                        chek2.Checked = false;
                    }
                }
                break;

            case 5:

                foreach (Control c6 in MenuItemStok.PageViews[5].Controls)
                {
                    if (c6 is CrmControls.CrmTextBox)
                    {
                        CrmControls.CrmTextBox text6 = c6 as CrmControls.CrmTextBox;
                        text6.Text = "";
                    }
                    if (c6 is CrmControls.CrmDropDown)
                    {
                        CrmControls.CrmDropDown drop3 = c6 as CrmControls.CrmDropDown;
                        if (drop3.SelectedIndex != -1)
                            drop3.SelectedIndex = 0;
                    }
                }
                break;

        }
    }
    #endregion

    #region Kayıt Yap
    private void StokKayit()
    {
        stok = new Db_Stok();
        stok.Create_Date = DateTime.Now;
        stok.Create_User = 1;
        stok.Hidden = true;
        stok.Locked = true;
        stok.Stok_Adi = txtStokAdi.Text;
        stok.Stok_Adi2 = txtStokAdi2.Text;
        if (chkStokAktif.Checked)
            stok.Stok_Aktif = true;
        else
            stok.Stok_Aktif = false;
        if (drpStokAlisBirim.SelectedIndex != -1)
            stok.Stok_Alis_Birim = int.Parse(drpStokAlisBirim.SelectedValue);
        if (chkStokAlisKapali.Checked)
            stok.Stok_Alis_Kapali = true;
        else
            stok.Stok_Alis_Kapali = false;
        if (drpStokAlisKdv.SelectedIndex != -1)
            stok.Stok_Alis_Kdv = int.Parse(drpStokAlisKdv.SelectedItem.Value);
        stok.Stok_Bilgi1 = txtStokBilgi1.Text;
        stok.Stok_Bilgi2 = txtStokBilgi2.Text;
        stok.Stok_Bilgi3 = txtStokBilgi3.Text;
        stok.Stok_Bilgi4 = txtStokBilgi4.Text;
        stok.Stok_Bilgi5 = txtStokBilgi5.Text;
        if (drpStokDovizTipi.SelectedIndex != -1)
            stok.Stok_Doviz_Tipi = int.Parse(drpStokDovizTipi.SelectedItem.Value);
        if (drpStokEksiKontrol.SelectedIndex != -1)
            stok.Stok_Eksi_Kontrol = Int16.Parse(drpStokEksiKontrol.SelectedValue);
        stok.Stok_Etiket_Adi = txtStokEtiketAdi.Text;
        //stok.Stok_Garanti_Suresi=
        if (drpStokIadeKdv.SelectedIndex != -1)
            stok.Stok_Iade_Kdv = drpStokIadeKdv.SelectedItem.Value;
        //stok.Stok_Iskonto_ID=
        if (txtStokIskontoOrani.Text != "")
            stok.Stok_Iskonto_Oran = decimal.Parse(txtStokIskontoOrani.Text);
        if (chkStokIskontoYapilsin.Checked)
            stok.Stok_Iskonto_Yapilsin = true;
        else
            stok.Stok_Iskonto_Yapilsin = false;
        //stok.Stok_Izleme_Yontemi
        //stok.Stok_Kar_Orani
        stok.Stok_Kasa_Adi = txtStokKasaAdi.Text;
        if (chkStokKasayaGonder.Checked)
            stok.Stok_Kasaya_Gonder = true;
        else
            stok.Stok_Kasaya_Gonder = false;
        stok.Stok_Kodu = txtStokKodu.Text;
        //stok.Stok_Mal_Kabul_Gun1
        if (txtStokMaxSeviye.Text != "")
            stok.Stok_Max_Seviye = decimal.Parse(txtStokMaxSeviye.Text);
        if (txtStokMinSeviye.Text != "")
            stok.Stok_Min_Seviye = decimal.Parse(txtStokMinSeviye.Text);
        if (txtStokMuhasebeId.Text != "")
            stok.Stok_Muhkod_ID = int.Parse(txtStokMuhasebeId.Text);
        //stok.Stok_Odeme_Sekli
        //stok.Stok_Ort_Devir_Hizi
        if (txtStokOtvId.Text != "")
            stok.Stok_Otv_ID = int.Parse(txtStokOtvId.Text);
        if (drpStokPerIadeKdv.SelectedIndex != -1)
            stok.Stok_Per_Iade_Kdv = int.Parse(drpStokPerIadeKdv.SelectedItem.Value);
        if (drpStokPerSatisKdv.SelectedIndex != -1)
            stok.Stok_Per_Satis_Kdv = int.Parse(drpStokPerSatisKdv.SelectedItem.Value);
        if (txtStokPrimOrani.Text != "")
            stok.Stok_Prim_Oran = decimal.Parse(txtStokPrimOrani.Text);
        if (txtStokPuan.Text != "")
            stok.Stok_Puan = decimal.Parse(txtStokPuan.Text);
        if (txtStokRafOmru.Text != "")
            stok.Stok_Raf_Omru = int.Parse(txtStokRafOmru.Text);
        //if (ViewState["resimpath"] != null)
        //    stok.Stok_Resim_Yolu = ViewState["resimpath"].ToString();
        if (drpStokSatisBirim.SelectedIndex != -1)
            stok.Stok_Satis_Birim = int.Parse(drpStokSatisBirim.SelectedValue);
        if (chkStokSatisKapali.Checked)
            stok.Stok_Satis_Kapali = true;
        else
            stok.Stok_Satis_Kapali = false;
        if (drpStokSatisKdv.SelectedIndex != -1)
            stok.Stok_Satis_Kdv = int.Parse(drpStokSatisKdv.SelectedItem.Value);
        //stok.Stok_Sip_Gun1
        if (chkStokSiparisKapali.Checked)
            stok.Stok_Sip_Kapali = true;
        else
            stok.Stok_Sip_Kapali = false;
        if (txtStokSipSeviye.Text != "")
            stok.Stok_Sip_Seviye = decimal.Parse(txtStokSipSeviye.Text);
        if (txtStokSpecial1.Text != "")
            stok.Stok_Special1 = int.Parse(txtStokSpecial1.Text);
        if (txtStokSpecial10.Text != "")
            stok.Stok_Special10 = int.Parse(txtStokSpecial10.Text);
        if (txtStokSpecial2.Text != "")
            stok.Stok_Special2 = int.Parse(txtStokSpecial2.Text);
        if (txtStokSpecial3.Text != "")
            stok.Stok_Special3 = int.Parse(txtStokSpecial3.Text);
        if (txtStokSpecial4.Text != "")
            stok.Stok_Special4 = int.Parse(txtStokSpecial4.Text);
        if (txtStokSpecial5.Text != "")
            stok.Stok_Special5 = int.Parse(txtStokSpecial5.Text);
        if (txtStokSpecial6.Text != "")
            stok.Stok_Special6 = int.Parse(txtStokSpecial6.Text);
        if (txtStokSpecial7.Text != "")
            stok.Stok_Special7 = int.Parse(txtStokSpecial7.Text);
        if (txtStokSpecial8.Text != "")
            stok.Stok_Special8 = int.Parse(txtStokSpecial8.Text);
        if (txtStokSpecial9.Text != "")
            stok.Stok_Special9 = int.Parse(txtStokSpecial9.Text);
        if (chkStokTeraziyeGonder.Checked)
            stok.Stok_Teraziye_Gonder = true;
        else
            stok.Stok_Teraziye_Gonder = false;
        if (drpStokTevkifat.SelectedIndex != -1)
            stok.Stok_Tevkifat = int.Parse(drpStokTevkifat.SelectedValue);
        if (drpStokUrunTip.SelectedIndex != -1)
            stok.Stok_Urun_Tip = Int16.Parse(drpStokUrunTip.SelectedValue);
        stok.Stok_Yabanci_Adi = txtStokYabanciAdi.Text;
        stok.Update_Date = DateTime.Now;
        stok.Update_User = 1;
        stok.Save();
        StokID(txtStokKodu.Text);

    }
    private void BirimKayit()
    {
        birim = new Db_Birim();
        birim.Birim_Adi = txtBirimAdi.Text;
        if (txtBirimBoy.Text != "")
            birim.Birim_Boy = decimal.Parse(txtBirimBoy.Text);
        if (txtBirimBrtAgirlik.Text != "")
            birim.Birim_Brt_Agirlik = decimal.Parse(txtBirimBrtAgirlik.Text);
        if (txtBirimDaraAgirlik.Text != "")
            birim.Birim_Dara_Agirlik = decimal.Parse(txtBirimDaraAgirlik.Text);
        if (txtBirimEn.Text != "")
            birim.Birim_EN = decimal.Parse(txtBirimEn.Text);
        if (txtBirimKatsayi.Text != "")
            birim.Birim_Katsayi = int.Parse(txtBirimKatsayi.Text);
        birim.Birim_Kod = txtBirimKod.Text;
        if (txtBirimNetAgirlik.Text != "")
            birim.Birim_Net_Agirlik = decimal.Parse(txtBirimNetAgirlik.Text);
        if (txtBirimYukseklik.Text != "")
            birim.Birim_Yukseklik = decimal.Parse(txtBirimYukseklik.Text);
        if (hdnStokid.Value != "")
            birim.Birim_Stok_ID = int.Parse(hdnStokid.Value);
        birim.Create_Date = DateTime.Now;
        birim.Create_User = 1;
        birim.Hidden = true;
        birim.Locked = true;
        birim.Update_Date = DateTime.Now;
        birim.Update_User = 1;
        birim.Save();
    }
    private void BarkodKayit()
    {
        barkod = new Db_Barkot();
        if (drpBarkodBirimID.SelectedIndex != -1)
            barkod.Barkod_Birim_ID = int.Parse(drpBarkodBirimID.SelectedItem.Value);
        if (drpBarkodIcerik.SelectedIndex != -1)
            barkod.Barkod_Icerik = Int16.Parse(drpBarkodIcerik.SelectedItem.Value);
        barkod.Barkod_Kod = txtBarkodKod.Text;
        if (drpBarkodTip.SelectedIndex!= -1)
            barkod.Barkod_Tip = Int16.Parse(drpBarkodTip.SelectedItem.Value);
        if (hdnStokid.Value != "")
            barkod.Barkod_Stok_ID = int.Parse(hdnStokid.Value);
        barkod.Create_Date = DateTime.Now;
        barkod.Create_User = 1;
        barkod.Hidden = true;
        barkod.Locked = true;
        barkod.Update_Date = DateTime.Now;
        barkod.Update_User = 1;
        barkod.Save();
    }
    private void StokDepoKayit()
    {

        stokDepo = new Db_Stok_Depo();
        stokDepo.Create_Date = DateTime.Now;
        stokDepo.Create_User = 1;
        if (chkDepoAlisKapali.Checked)
            stokDepo.DepoAlisKapali = true;
        else
            stokDepo.DepoAlisKapali = false;
        if (drpDepoEksiKontrol.SelectedIndex!= -1)
            stokDepo.DepoEksiKontrol = Int16.Parse(drpDepoEksiKontrol.SelectedValue);
        if (hdnStokid.Value != "")
            stokDepo.DepoID = int.Parse(hdnStokid.Value);
        if (chkDepoMalKabulGun1.Checked)
            stokDepo.DepoMalKabulGun1 = true;
        else
            stokDepo.DepoMalKabulGun1 = false;
        if (chkDepoMalKabulGun2.Checked)
            stokDepo.DepoMalKabulGun2 = true;
        else
            stokDepo.DepoMalKabulGun2 = false;
        if (chkDepoMalKabulGun3.Checked)
            stokDepo.DepoMalKabulGun3 = true;
        else
            stokDepo.DepoMalKabulGun3 = false;
        if (chkDepoMalKabulGun4.Checked)
            stokDepo.DepoMalKabulGun4 = true;
        else
            stokDepo.DepoMalKabulGun4 = false;
        if (chkDepoMalKabulGun5.Checked)
            stokDepo.DepoMalKabulGun5 = true;
        else
            stokDepo.DepoMalKabulGun5 = false;
        if (chkDepoMalKabulGun6.Checked)
            stokDepo.DepoMalKabulGun6 = true;
        else
            stokDepo.DepoMalKabulGun6 = false;
        if (chkDepoMalKabulGun7.Checked)
            stokDepo.DepoMalKabulGun7 = true;
        else
            stokDepo.DepoMalKabulGun7 = false;
        if (txtDepoMaxSeviye.Text != "")
            stokDepo.DepoMaxSeviye = int.Parse(txtDepoMaxSeviye.Text);
        if (txtDepoMinSeviye.Text != "")
            stokDepo.DepoMinSeviye = int.Parse(txtDepoMinSeviye.Text);
        if (chkDepoSatisKapali.Checked)
            stokDepo.DepoSatisKapali = true;
        else
            stokDepo.DepoSatisKapali = false;
        if (chkdepo_sip_gun1.Checked)
            stokDepo.DepoSipGun1 = true;
        else
            stokDepo.DepoSipGun1 = false;
        if (chkdepo_sip_gun2.Checked)
            stokDepo.DepoSipGun2 = true;
        else
            stokDepo.DepoSipGun2 = false;
        if (chkdepo_sip_gun3.Checked)
            stokDepo.DepoSipGun3 = true;
        else
            stokDepo.DepoSipGun3 = false;
        if (chkdepo_sip_gun4.Checked)
            stokDepo.DepoSipGun4 = true;
        else
            stokDepo.DepoSipGun4 = false;
        if (chkdepo_sip_gun5.Checked)
            stokDepo.DepoSipGun5 = true;
        else
            stokDepo.DepoSipGun5 = false;
        if (chkdepo_sip_gun6.Checked)
            stokDepo.DepoSipGun6 = true;
        else
            stokDepo.DepoSipGun6 = false;
        if (chkdepo_sip_gun7.Checked)
            stokDepo.DepoSipGun7 = true;
        else
            stokDepo.DepoSipGun7 = false;
        if (chkDepoSipKapali.Checked)
            stokDepo.DepoSipKapali = true;
        else
            stokDepo.DepoSipKapali = false;
        if (txtDepoSipSure.Text != "")
            stokDepo.DepoSipSure = int.Parse(txtDepoSipSure.Text);
        //stokDepo.DepoStokID
        stokDepo.Hidden = true;
        stokDepo.Locked = true;
        //if (drpDepoKod.SelectedIndex!= -1)
        //Değişecek-------------
        if (drpDepoKod.SelectedIndex!= -1)
            stokDepo.SDepoDepoID = int.Parse(drpDepoKod.SelectedItem.Value);
        if (hdnStokid.Value != "")
            stokDepo.DepoStokID = int.Parse(hdnStokid.Value);
        //------------------
        stokDepo.Update_Date = DateTime.Now;
        stokDepo.Update_User = 1;
        stokDepo.Save();

    }
    private void FiyatKayit()
    {
        fiyat = new Db_Fiyat();
        fiyat.Create_Date = DateTime.Now;
        fiyat.Create_User = 1;
        if (txtFiyat.Text != "")
            fiyat.Fiyat = decimal.Parse(txtFiyat.Text);
        if (drpFiyatBirimNo.SelectedIndex!= -1)
            fiyat.Fiyat_Birim_ID = int.Parse(drpFiyatBirimNo.SelectedItem.Value);
        if (drpFiyatDepoID.SelectedIndex!= -1)
            fiyat.Fiyat_Depo_ID = int.Parse(drpFiyatDepoID.SelectedItem.Value);
        if (drpFiyatKod.SelectedIndex!= -1)
            fiyat.Fiyat_Kod = int.Parse(drpFiyatKod.SelectedItem.Value);
        if (hdnStokid.Value != "")
            fiyat.Fiyat_Stok_ID = int.Parse(hdnStokid.Value);
        fiyat.Hidden = true;
        fiyat.Locked = true;
        fiyat.Update_Date = DateTime.Now;
        fiyat.Update_User = 1;
        fiyat.Save();
    }
    #endregion

    #region Kayıt Bul
    private void StokKayitBul(string id)
    {
        stok = new Db_Stok();
        if (id != "")
        {
            stok.Stok_Kodu = id;
            stok.KayitBul();
            txtStokAdi.Text = stok.Stok_Adi;
            txtStokAdi2.Text = stok.Stok_Adi2;
            if (stok.Stok_Aktif == true)
                chkStokAktif.Checked = true;
            else
                chkStokAktif.Checked = false;
            if (stok.Stok_Alis_Birim != 0)
                drpStokAlisBirim.SelectedValue = stok.Stok_Alis_Birim.ToString();
            if (stok.Stok_Alis_Kapali == true)
                chkStokAlisKapali.Checked = true;
            else
                chkStokAlisKapali.Checked = false;
            if (stok.Stok_Alis_Kdv != 0)
            {
                drpStokAlisKdv.SelectedValue = stok.Stok_Alis_Kdv.ToString();
            }
            txtStokBilgi1.Text = stok.Stok_Bilgi1;
            txtStokBilgi2.Text = stok.Stok_Bilgi2;
            txtStokBilgi3.Text = stok.Stok_Bilgi3;
            txtStokBilgi4.Text = stok.Stok_Bilgi4;
            txtStokBilgi5.Text = stok.Stok_Bilgi5;
            if (stok.Stok_Doviz_Tipi != 0)
                drpStokDovizTipi.SelectedValue = stok.Stok_Doviz_Tipi.ToString();
            if (stok.Stok_Eksi_Kontrol != 0)
                drpStokEksiKontrol.SelectedValue = stok.Stok_Eksi_Kontrol.ToString();
            txtStokEtiketAdi.Text = stok.Stok_Etiket_Adi;
            //stok.Stok_Garanti_Suresi=
            if (stok.Stok_Iade_Kdv != null)
                drpStokIadeKdv.SelectedValue = stok.Stok_Iade_Kdv.ToString();
            //stok.Stok_Iskonto_ID=
            if (stok.Stok_Iskonto_Oran != 0)
                txtStokIskontoOrani.Text = stok.Stok_Iskonto_Oran.ToString();
            //stok.Stok_Iskonto_Yapilsin
            //stok.Stok_Izleme_Yontemi
            //stok.Stok_Kar_Orani
            txtStokKasaAdi.Text = stok.Stok_Kasa_Adi;
            if (stok.Stok_Kasaya_Gonder == true)
                chkStokKasayaGonder.Checked = true;
            else
                chkStokKasayaGonder.Checked = false;
            txtStokKodu.Text = stok.Stok_Kodu;
            //stok.Stok_Mal_Kabul_Gun1
            if (stok.Stok_Max_Seviye != 0)
                txtStokMaxSeviye.Text = stok.Stok_Max_Seviye.ToString();
            if (stok.Stok_Min_Seviye != 0)
                txtStokMinSeviye.Text = stok.Stok_Min_Seviye.ToString();
            if (stok.Stok_Muhkod_ID != 0)
                txtStokMuhasebeId.Text = stok.Stok_Muhkod_ID.ToString();
            //stok.Stok_Odeme_Sekli
            //stok.Stok_Ort_Devir_Hizi
            if (stok.Stok_Otv_ID != 0)
                txtStokOtvId.Text = stok.Stok_Otv_ID.ToString();
            if (stok.Stok_Per_Iade_Kdv != 0)
                drpStokPerIadeKdv.SelectedValue = stok.Stok_Per_Iade_Kdv.ToString();
            if (stok.Stok_Per_Satis_Kdv != 0)
                drpStokPerSatisKdv.SelectedValue = stok.Stok_Per_Satis_Kdv.ToString();
            if (stok.Stok_Prim_Oran != 0)
                txtStokPrimOrani.Text = stok.Stok_Prim_Oran.ToString();
            if (stok.Stok_Puan != 0)
                txtStokPuan.Text = stok.Stok_Puan.ToString();
            if (stok.Stok_Raf_Omru != 0)
                txtStokRafOmru.Text = stok.Stok_Raf_Omru.ToString();
            //if (stok.Stok_Resim_Yolu != "")
            //    imgStokResim.ImageUrl = stok.Stok_Resim_Yolu;
            if (stok.Stok_Satis_Birim != 0)
                drpStokSatisBirim.SelectedValue = stok.Stok_Satis_Birim.ToString();
            if (stok.Stok_Satis_Kapali == true)
                chkStokSatisKapali.Checked = true;
            else
                chkStokSatisKapali.Checked = false;
            if (stok.Stok_Satis_Kdv != 0)
                drpStokSatisKdv.SelectedValue = stok.Stok_Satis_Kdv.ToString();
            //stok.Stok_Sip_Gun1
            if (stok.Stok_Sip_Kapali == true)
                chkStokSiparisKapali.Checked = true;
            else
                chkStokSiparisKapali.Checked = false;
            if (stok.Stok_Sip_Seviye != 0)
                txtStokSipSeviye.Text = stok.Stok_Sip_Seviye.ToString();
            if (stok.Stok_Special1 != 0)
                txtStokSpecial1.Text = stok.Stok_Special1.ToString();
            if (stok.Stok_Special10 != 0)
                txtStokSpecial10.Text = stok.Stok_Special10.ToString();
            if (stok.Stok_Special2 != 0)
                txtStokSpecial2.Text = stok.Stok_Special2.ToString();
            if (stok.Stok_Special3 != 0)
                txtStokSpecial3.Text = stok.Stok_Special3.ToString();
            if (stok.Stok_Special4 != 0)
                txtStokSpecial4.Text = stok.Stok_Special4.ToString();
            if (stok.Stok_Special5 != 0)
                txtStokSpecial5.Text = stok.Stok_Special5.ToString();
            if (stok.Stok_Special6 != 0)
                txtStokSpecial6.Text = stok.Stok_Special6.ToString();
            if (stok.Stok_Special7 != 0)
                txtStokSpecial7.Text = stok.Stok_Special7.ToString();
            if (stok.Stok_Special8 != 0)
                txtStokSpecial8.Text = stok.Stok_Special8.ToString();
            if (stok.Stok_Special9 != 0)
                txtStokSpecial9.Text = stok.Stok_Special9.ToString();
            if (stok.Stok_Teraziye_Gonder == true)
                chkStokTeraziyeGonder.Checked = true;
            else
                chkStokTeraziyeGonder.Checked = false;
            if (stok.Stok_Iskonto_Yapilsin)
                chkStokIskontoYapilsin.Checked = true;
            else
                chkStokIskontoYapilsin.Checked = false;
            if (stok.Stok_Tevkifat != 0)
                drpStokTevkifat.SelectedItem.Value = stok.Stok_Tevkifat.ToString();
            if (stok.Stok_Urun_Tip != 0)
                drpStokUrunTip.SelectedItem.Value = stok.Stok_Urun_Tip.ToString();
            txtStokYabanciAdi.Text = stok.Stok_Yabanci_Adi;
            hdnStokid.Value = stok.ID.ToString();
            GrdViewBirimler.DataSource = BirimList(stok.ID);
            GrdViewBirimler.DataBind();
            GridViewBarkodBilgileri.DataSource = BarkodList(stok.ID);
            GridViewBarkodBilgileri.DataBind();
            GridViewDepoDetaylar.DataSource = DepoDetayList(stok.ID);
            GridViewDepoDetaylar.DataBind();
            GrdViewFiyat.DataSource = FiyatDetayList(stok.ID);
            GrdViewFiyat.DataBind();
        }
    }
    private void StokID(string id)
    {
        stok = new Db_Stok();
        stok.Stok_Kodu = id;
        stok.KayitBul();
        hdnStokid.Value = stok.ID.ToString();
    }
    private void BarkodKayitBul(string id)
    {
        barkod = new Db_Barkot();
        barkod.Barkod_Kod = id;
        barkod.KayitBul();
        if (barkod.Barkod_Birim_ID != 0)
            drpBarkodBirimID.SelectedValue = barkod.Barkod_Birim_ID.ToString();
        txtBarkodKod.Text = barkod.Barkod_Kod;
        drpBarkodTip.SelectedValue = barkod.Barkod_Tip.ToString();
        drpBarkodIcerik.SelectedValue = barkod.Barkod_Icerik.ToString();
        drpBarkodBirimID.SelectedValue = barkod.Barkod_Birim_ID.ToString();

    }
    private DataTable BirimList(int stokid)
    {
        birim = new Db_Birim();
        List<String> select = new List<string>();
        select.Add("birim_kod as [Birim Kodu]");
        select.Add("birim_adi as [Birim Adı]");
        select.Add("birim_katsayi as [Katsayısı]");
        return birim.GetAllRecord_Datatable(select.ToArray(), "birim_stok_id =" + stokid.ToString());
    }
    private DataTable BarkodList(int stokid)
    {
        barkod = new Db_Barkot();
        return barkod.GetAllRecord_Datatable2("SELECT TBL_0_BARKOD.barkod_kod AS Barkod, TBL_0_BARKOD.barkod_tip AS [Tip Adı], TBL_0_BARKOD.barkod_icerik AS İçerik, TBL_0_BIRIM.birim_kod AS [Birim Kod], TBL_0_BIRIM.birim_adi AS [Birim Adi] FROM TBL_0_BARKOD INNER JOIN TBL_0_BIRIM ON TBL_0_BARKOD.barkod_birim_id = TBL_0_BIRIM.birim_id WHERE   (TBL_0_BARKOD.barkod_stok_id =" + stokid.ToString() + ")");
    }
    private DataTable DepoDetayList(int stokid)
    {
        stokDepo = new Db_Stok_Depo();
        return stokDepo.GetAllRecord_Datatable2("SELECT  TBL_0_DEPO.depo_kodu AS [Depo Kodu], TBL_0_DEPO.depo_adi AS [Depo Adı], TBL_0_STOK_DEPO.sdepo_min_seviye AS [Min Seviye], TBL_0_STOK_DEPO.sdepo_max_seviye AS [Max Seviye], TBL_0_STOK_DEPO.sdepo_sip_sure AS [Sipariş Süresi] FROM  TBL_0_STOK_DEPO INNER JOIN TBL_0_DEPO ON TBL_0_STOK_DEPO.sdepo_depo_id = TBL_0_DEPO.depo_id WHERE (TBL_0_STOK_DEPO.sdepo_stok_id =" + stokid + ")");
    }
    private DataTable FiyatDetayList(int stokid)
    {
        fiyat = new Db_Fiyat();
        return fiyat.GetAllRecord_Datatable2("SELECT fiyat_kod AS [Fiyat Kod], fiyat_depo_id AS [Depo Kod], fiyat_birim_id AS [Birim Kod], fiyat AS Fiyat FROM  TBL_0_FIYAT WHERE fiyat_stok_id =" + stokid);
    }
    private void FiyatKayitBul(int id, int idstok, int idbirim, int iddepo)
    {
        fiyat = new Db_Fiyat();
        fiyat.Fiyat_Kod = id;
        fiyat.Fiyat_Stok_ID = idstok;
        fiyat.Fiyat_Depo_ID = iddepo;
        fiyat.Fiyat_Birim_ID = idbirim;
        fiyat.KayitBul();
        txtFiyat.Text = fiyat.Fiyat.ToString();
        drpFiyatBirimNo.SelectedValue = fiyat.Fiyat_Birim_ID.ToString();
        drpFiyatDepoID.SelectedItem.Value = fiyat.Fiyat_Depo_ID.ToString();
        drpFiyatKod.SelectedValue = fiyat.Fiyat_Kod.ToString();
    }
    private void BirimKayitBul(string id, int id2)
    {
        birim = new Db_Birim();
        birim.Birim_Kod = id;
        birim.Birim_Stok_ID = id2;
        birim.KayitBul();
        txtBirimAdi.Text = birim.Birim_Adi;
        if (birim.Birim_Boy != 0)
            txtBirimBoy.Text = birim.Birim_Boy.ToString();
        if (birim.Birim_Brt_Agirlik != 0)
            txtBirimBrtAgirlik.Text = birim.Birim_Brt_Agirlik.ToString();
        if (birim.Birim_Dara_Agirlik != 0)
            txtBirimDaraAgirlik.Text = birim.Birim_Dara_Agirlik.ToString();
        if (birim.Birim_EN != 0)
            txtBirimEn.Text = birim.Birim_EN.ToString();
        if (birim.Birim_Katsayi != 0)
            txtBirimKatsayi.Text = birim.Birim_Katsayi.ToString();
        txtBirimKod.Text = birim.Birim_Kod;
        if (birim.Birim_Net_Agirlik != 0)
            txtBirimNetAgirlik.Text = birim.Birim_Net_Agirlik.ToString();
        if (birim.Birim_Yukseklik != 0)
            txtBirimYukseklik.Text = birim.Birim_Yukseklik.ToString();
    }
    private void StokDepoKayitBul(string stokid, string depoid)
    {
        stokDepo = new Db_Stok_Depo();
        stokDepo.DepoStokID = Convert.ToInt32(stokid);
        stokDepo.SDepoDepoID = Convert.ToInt32(depoid);
        stokDepo.KayitBul();
        if (stokDepo.DepoAlisKapali)
            chkDepoAlisKapali.Checked = true;
        else
            chkDepoAlisKapali.Checked = false;
        if (stokDepo.DepoEksiKontrol != 0)
            drpDepoEksiKontrol.SelectedValue = stokDepo.DepoEksiKontrol.ToString();

        if (stokDepo.DepoMalKabulGun1)
            chkDepoMalKabulGun1.Checked = true;
        else
            chkDepoMalKabulGun1.Checked = false;
        if (stokDepo.DepoMalKabulGun2)
            chkDepoMalKabulGun2.Checked = true;
        else
            chkDepoMalKabulGun2.Checked = false;
        if (stokDepo.DepoMalKabulGun3)
            chkDepoMalKabulGun3.Checked = true;
        else
            chkDepoMalKabulGun3.Checked = false;
        if (stokDepo.DepoMalKabulGun4)
            chkDepoMalKabulGun4.Checked = true;
        else
            chkDepoMalKabulGun4.Checked = false;
        if (stokDepo.DepoMalKabulGun5)
            chkDepoMalKabulGun5.Checked = true;
        else
            chkDepoMalKabulGun5.Checked = false;
        if (stokDepo.DepoMalKabulGun6)
            chkDepoMalKabulGun6.Checked = true;
        else
            chkDepoMalKabulGun6.Checked = false;
        if (stokDepo.DepoMalKabulGun7)
            chkDepoMalKabulGun7.Checked = true;
        else
            chkDepoMalKabulGun7.Checked = false;
        if (stokDepo.DepoMaxSeviye != 0)
            txtDepoMaxSeviye.Text = stokDepo.DepoMaxSeviye.ToString();
        if (stokDepo.DepoMinSeviye != 0)
            txtDepoMinSeviye.Text = stokDepo.DepoMinSeviye.ToString();
        if (stokDepo.DepoSatisKapali)
            chkDepoSatisKapali.Checked = true;
        else
            chkDepoSatisKapali.Checked = false;
        if (stokDepo.DepoSipGun1)
            chkdepo_sip_gun1.Checked = true;
        else
            stokDepo.DepoSipGun1 = false;
        if (stokDepo.DepoSipGun2)
            chkdepo_sip_gun2.Checked = true;
        else
            chkdepo_sip_gun2.Checked = false;
        if (stokDepo.DepoSipGun3)
            chkdepo_sip_gun3.Checked = true;
        else
            chkdepo_sip_gun3.Checked = false;
        if (stokDepo.DepoSipGun4)
            chkdepo_sip_gun4.Checked = true;
        else
            chkdepo_sip_gun4.Checked = false;
        if (stokDepo.DepoSipGun5)
            chkdepo_sip_gun5.Checked = true;
        else
            chkdepo_sip_gun5.Checked = false;
        if (stokDepo.DepoSipGun6)
            chkdepo_sip_gun6.Checked = true;
        else
            chkdepo_sip_gun6.Checked = false;
        if (stokDepo.DepoSipGun7)
            chkdepo_sip_gun7.Checked = true;
        else
            chkdepo_sip_gun7.Checked = false;
        if (stokDepo.DepoSipKapali)
            chkDepoSipKapali.Checked = true;
        else
            chkDepoSipKapali.Checked = false;
        if (stokDepo.DepoSipSure != 0)
            txtDepoSipSure.Text = stokDepo.DepoSipSure.ToString();



    }

    #endregion

    #region image Attribute Add
    private void AttributesAdd()
    {
        imgStokKodu.Attributes.Add("onclick", "OpenPageStok('stok=true');");
        imgStokAdi.Attributes.Add("onclick", "OpenPageStok('stok=true');");
        imgStokAdi2.Attributes.Add("onclick", "OpenPageStok('stok=true');");
        imgStokMuhasebeId.Attributes.Add("onclick", "OpenPageStok('stok=true');");
        imgStokOtvId.Attributes.Add("onclick", "OpenPageStok('stok=true');");
        imgbtnKaydetKapat.Attributes.Add("onclick", "return KayitKontrol();");
        imgbtnKaydet.Attributes.Add("onclick", "return KayitKontrol();");
        imgbtnSil.Attributes.Add("onclick", "return KayitKontrol();");
    }
    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString.Count > 0)
        {
            if (!IsPostBack)
            {
                StokKayitBul(Request["id"].ToString());

            }
        }
        AttributesAdd();
    }

    protected override void OnInitComplete(EventArgs e)
    {
        if (!IsPostBack)
        {
            DropDepo();
            DropBirim();
            DropDovizKdv();
            DropFiyatKod();
        }
        base.OnInitComplete(e);
    }

    protected void imgbtnKaydet_Click(object sender, ImageClickEventArgs e)
    {
        if (MenuItemStok.SelectedIndex == 0 || MenuItemStok.SelectedIndex == 1)
        {
            StokKayit();
            ClearArea();
        }
        else if (MenuItemStok.SelectedIndex == 2)
        {
            BirimKayit();
            GrdViewBirimler.DataSource = BirimList(int.Parse(hdnStokid.Value));
            GrdViewBirimler.DataBind();
            DropBirim(int.Parse(hdnStokid.Value));
            ClearArea();
        }
        if (MenuItemStok.SelectedIndex == 3)
        {
            BarkodKayit();
            GridViewBarkodBilgileri.DataSource = BarkodList(int.Parse(hdnStokid.Value));
            GridViewBarkodBilgileri.DataBind();
            ClearArea();
        }
        else if (MenuItemStok.SelectedIndex == 4)
        {
            StokDepoKayit();
            GridViewDepoDetaylar.DataSource = DepoDetayList(int.Parse(hdnStokid.Value));
            GridViewDepoDetaylar.DataBind();
            ClearArea();
        }
        else if (MenuItemStok.SelectedIndex == 5)
        {
            FiyatKayit();
            GrdViewFiyat.DataSource = FiyatDetayList(int.Parse(hdnStokid.Value));
            GrdViewFiyat.DataBind();
            ClearArea();
        }
        this.ClientScript.RegisterStartupScript(typeof(Page), "Tazele", "Refresh();", true);
    }

    protected void imgbtnKaydetKapat_Click(object sender, ImageClickEventArgs e)
    {
        if (MenuItemStok.SelectedIndex == 0 || MenuItemStok.SelectedIndex == 1)
        {
            StokKayit();
        }
        else if (MenuItemStok.SelectedIndex == 2)
        {
            BirimKayit();
        }
        if (MenuItemStok.SelectedIndex == 3)
        {
            BarkodKayit();
        }
        else if (MenuItemStok.SelectedIndex == 4)
        {
            StokDepoKayit();
        }
        else if (MenuItemStok.SelectedIndex == 5)
        {
            FiyatKayit();
        }
        this.ClientScript.RegisterStartupScript(typeof(Page), "Close", "PageClose();", true);
    }

    protected void imgbtnSil_Click(object sender, ImageClickEventArgs e)
    {
        int selectedTab = MenuItemStok.SelectedIndex;
        switch (selectedTab)
        {
            case 0:
                stok = new Db_Stok();
                if (txtStokKodu.Text != "")
                {
                    stok.Stok_Kodu = txtStokKodu.Text;
                    stok.KayitSil();
                    foreach (Control c in MenuItemStok.PageViews[0].Controls)
                    {
                        if (c is CrmControls.CrmTextBox)
                        {
                            CrmControls.CrmTextBox textbox = c as CrmControls.CrmTextBox;
                            textbox.Text = "";
                        }
                        if (c is CrmControls.CrmDropDown)
                        {
                            CrmControls.CrmDropDown dropkdv = c as CrmControls.CrmDropDown;
                            if (dropkdv.SelectedIndex != -1)
                                dropkdv.SelectedIndex = 0;
                        }
                    }
                    foreach (Control c2 in MenuItemStok.PageViews[1].Controls)
                    {
                        if (c2 is CrmControls.CrmTextBox)
                        {
                            CrmControls.CrmTextBox textbox = c2 as CrmControls.CrmTextBox;
                            textbox.Text = "";
                        }
                        if (c2 is CrmControls.CrmCheckBox)
                        {
                            CrmControls.CrmCheckBox chek = c2 as CrmControls.CrmCheckBox;
                            chek.Checked = false;
                        }
                        if (c2 is CrmControls.CrmDropDown)
                        {
                            CrmControls.CrmDropDown dropkrs = c2 as CrmControls.CrmDropDown;
                            if (dropkrs.SelectedIndex != -1)
                                dropkrs.SelectedIndex = 0;
                        }
                    }

                }
                break;
            case 2:
                birim = new Db_Birim();
                if (hdnStokid.Value != "" && txtBirimKod.Text != "")
                {
                    birim.Birim_Kod = txtBirimKod.Text;
                    birim.Birim_Stok_ID = int.Parse(hdnStokid.Value);
                    birim.KayitSil();
                    foreach (Control c3 in MenuItemStok.PageViews[2].Controls)
                    {
                        if (c3 is CrmControls.CrmTextBox)
                        {
                            CrmControls.CrmTextBox text3 = c3 as CrmControls.CrmTextBox;
                            text3.Text = "";
                        }
                    }

                }
                break;
            case 3:
                barkod = new Db_Barkot();
                if (txtBarkodKod.Text != "")
                {
                    barkod.Barkod_Kod = txtBarkodKod.Text;
                    barkod.KayitSil();
                    foreach (Control c4 in MenuItemStok.PageViews[3].Controls)
                    {
                        if (c4 is CrmControls.CrmTextBox)
                        {
                            CrmControls.CrmTextBox text4 = c4 as CrmControls.CrmTextBox;
                            text4.Text = "";
                        }
                        if (c4 is CrmControls.CrmDropDown)
                        {
                            CrmControls.CrmDropDown drop = c4 as CrmControls.CrmDropDown;
                            if (drop.SelectedIndex != -1)
                                drop.SelectedIndex = 0;
                        }
                    }
                }
                break;
            case 4:
                stokDepo = new Db_Stok_Depo();
                if (hdnStokid.Value != "")
                {
                    stokDepo.SDepoDepoID = int.Parse(drpDepoKod.SelectedItem.Value);
                    stokDepo.DepoStokID = int.Parse(hdnStokid.Value);
                    stokDepo.KayitSil();
                    foreach (Control c5 in MenuItemStok.PageViews[4].Controls)
                    {
                        if (c5 is CrmControls.CrmTextBox)
                        {
                            CrmControls.CrmTextBox text5 = c5 as CrmControls.CrmTextBox;
                            text5.Text = "";
                        }
                        if (c5 is CrmControls.CrmDropDown)
                        {
                            CrmControls.CrmDropDown drop2 = c5 as CrmControls.CrmDropDown;
                            if (drop2.SelectedIndex != -1)
                                drop2.SelectedIndex = 0;
                        }
                        if (c5 is CrmControls.CrmCheckBox)
                        {
                            CrmControls.CrmCheckBox chek2 = c5 as CrmControls.CrmCheckBox;
                            chek2.Checked = false;
                        }
                    }
                }
                break;
            case 5:
                fiyat = new Db_Fiyat();
                fiyat.Fiyat_Kod = int.Parse(drpFiyatKod.SelectedItem.Value);
                fiyat.Fiyat_Stok_ID = int.Parse(hdnStokid.Value);
                fiyat.Fiyat_Depo_ID = int.Parse(drpFiyatDepoID.SelectedItem.Value);
                fiyat.Fiyat_Birim_ID = int.Parse(drpFiyatBirimNo.SelectedItem.Value);
                foreach (Control c6 in MenuItemStok.PageViews[5].Controls)
                {
                    if (c6 is CrmControls.CrmTextBox)
                    {
                        CrmControls.CrmTextBox text6 = c6 as CrmControls.CrmTextBox;
                        text6.Text = "";
                    }
                    if (c6 is CrmControls.CrmDropDown)
                    {
                        CrmControls.CrmDropDown drop3 = c6 as CrmControls.CrmDropDown;
                        if (drop3.SelectedIndex != -1)
                            drop3.SelectedValue = "0";
                    }
                }
                break;
        }
        this.ClientScript.RegisterStartupScript(typeof(Page), "Yenile", "Refresh();", true);
    }

    //protected void btnResimEkle_Click(object sender, EventArgs e)
    //{
    //    if (FileUploadImage.HasFile)
    //    {
    //        FileUploadImage.PostedFile.SaveAs(Server.MapPath(".") + "\\Urun Resim\\" + FileUploadImage.FileName);
    //        //imgStokResim.ImageUrl = "~/Urun Resim/" + FileUploadImage.FileName;
    //        ViewState["resimpath"] = "~/Urun Resim/" + FileUploadImage.FileName;
    //    }
    //}

    protected void GrdViewBirimler_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (GrdViewBirimler.Rows[Convert.ToInt32(e.CommandArgument.ToString())].Cells[1].Text != "" && hdnStokid.Value != "")
            BirimKayitBul(GrdViewBirimler.Rows[Convert.ToInt32(e.CommandArgument.ToString())].Cells[1].Text.ToString(), int.Parse(hdnStokid.Value.ToString()));
    }

    protected void GridViewBarkodBilgileri_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (GridViewBarkodBilgileri.Rows[Convert.ToInt32(e.CommandArgument.ToString())].Cells[1].Text != "" && hdnStokid.Value != "")
            BarkodKayitBul(GridViewBarkodBilgileri.Rows[Convert.ToInt32(e.CommandArgument.ToString())].Cells[1].Text.ToString());
    }

    protected void GridViewDepoDetaylar_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (GridViewDepoDetaylar.Rows[Convert.ToInt32(e.CommandArgument.ToString())].Cells[1].Text != "" && hdnStokid.Value != "")
            StokDepoKayitBul(hdnStokid.Value.ToString(), GridViewDepoDetaylar.Rows[Convert.ToInt32(e.CommandArgument.ToString())].Cells[1].Text.ToString());
    }

    protected void GrdViewFiyat_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (GrdViewFiyat.Rows[int.Parse(e.CommandArgument.ToString())].Cells[1].Text != "")
        {
            int fiyatkod = int.Parse(GrdViewFiyat.Rows[int.Parse(e.CommandArgument.ToString())].Cells[1].Text.ToString());
            int depoid = int.Parse(GrdViewFiyat.Rows[int.Parse(e.CommandArgument.ToString())].Cells[2].Text.ToString());
            int birimid = int.Parse(GrdViewFiyat.Rows[int.Parse(e.CommandArgument.ToString())].Cells[3].Text.ToString());
            FiyatKayitBul(fiyatkod, int.Parse(hdnStokid.Value), birimid, depoid);
        }

    }

    protected void imgNewREcord_Click(object sender, ImageClickEventArgs e)
    {
        ClearArea();
    }

}
